<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.icss.th.subjects.pojo.Subject"%>
<%@ page import="com.icss.th.subjects.service.SubjectService"%>
<%@ page import="com.icss.th.fulltext.pojo.SearchResult"%>
<%@ page import="com.icss.th.common.Constants.SEARCH_TYPE"%>
<%@ page import="com.icss.th.db.pojo.PageInfo"%>
<%@ page import="com.icss.th.common.util.SecureUtil"%>
<%
	String context = request.getContextPath();
	String spendTime = (String)request.getAttribute("spendTime");
	PageInfo pageInfo = (PageInfo)request.getAttribute("pageInfo");
	List<SearchResult> results = (List<SearchResult>)request.getAttribute("list");
	
	String keyword = (String)request.getAttribute("keyword");
	String subjectId = (String)request.getAttribute("subjectId");
	String type = (String)request.getAttribute("type");
	if("".equals(type) || type == null)	type = SEARCH_TYPE.QUESTION;
	String unkeyword = (String)request.getAttribute("unkeyword");
	unkeyword = unkeyword == null? "" : unkeyword;
%>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>题海——考试、复习的最佳助手</title>
<meta name="Robots" content="All">
<meta name="description" content="题海题库题目搜索引擎,汇集了近年优秀质量的题库;是一个全国各种学历考试,资格认证考试的全真在线模拟考试网站,是各类考生考前辅导学习的练兵必备工具"/>
<meta name="keywords" content="题海,题海网,学霸,题库,考试答案,题海考试试题,题海试题库,历年真题,模拟试题,预测题,公务员,报关员,建造师,造价师,会计证,会计从业,会计师,经济师,证券资格考试,英语四六级考试,职称英语,公共英语,考研,自考,计算机等级"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="<%=context%>/includes/js/jquery.cookie.js"></script>
<script src="<%=context%>/includes/js/PagerView.js" type="text/javascript"></script>
<link href="<%=context%>/includes/css/PagerView.css" rel="stylesheet" type="text/css">
<link href="<%=context%>/includes/css/base.css" rel="stylesheet" />
<base target="_blank">
<style>
#list {
	line-height: 23px;
	margin: 0;
}
#list ul {
	margin-bottom: 20px;
	margin-left: -40px;
}
#list ul li {
	color: #666;
	list-style: none;
}
i {
	color: red;
}
.t {
	color: #03C;
	text-decoration: underline;
	font-size: 16px;
	line-height: 28px;
}
.t2 {
	color: #090;
}
</style>
</head>
<body>
<input type="hidden" name="pnum" id="pnum" value="">
<input type="hidden" name="type" id="type" value="<%=type%>">
<input type="hidden" name="unkeyword" id="unkeyword" value="<%=unkeyword%>">
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
  <div class="navbar-header">
    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse"> <span class="sr-only">TIHAI.ORG</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button>
    <a class="navbar-brand tihai-logo" href="/">&nbsp;</a> </div>
  <div class="collapse navbar-collapse navbar-ex1-collapse">
    <div class="navbar-form navbar-left" role="search">
      <div class="form-group">
        <input type="text" class="form-control" x-webkit-speech="x-webkit-speech" required value="<%=keyword%>" id="keyword" >
      </div>
      <button onclick="_submit()" class="btn btn-danger" type="button">搜索</button>
    </div>
  </div>
</nav>
<div class="container-fluid">
  <div class="row" id="m_list">
    <div class="col-sm-1"></div>
    <div class="col-sm-8">
      <button id="typeOption1" onclick="optionSubmit('1')" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span> &nbsp; 试题</button>
      <button id="typeOption2" onclick="optionSubmit('2')" class="btn btn-default btn-xs hidden"><span class="glyphicon glyphicon-list-alt"></span> &nbsp; 试卷</button>
      <input type="hidden" value="<%=subjectId%>" id="subjectId" name="subjectId" >
      <span class="btn  btn-default btn-xs" style="margin-left:30px;"  data-toggle="collapse" data-target="#subj">&nbsp;<span id="subjectName">
      <%
	  if (SubjectService.getSubjectName(subjectId) != null)
	  {out.println(SubjectService.getSubjectName(subjectId));}
	  else
	  {out.println("全部");}
	  //=SubjectService.getSubjectName(subjectId)
	  %>
      </span></span>&nbsp; <small class="text-danger">约<%=pageInfo.getRecordCount()%>条(<%=spendTime%>S)</small></div>
  </div>
  <%
		Subject root = SubjectService.getRoot();
		if (root != null)
		{
			List<Subject> list = root.getChildren();
			if (list  != null && !list.isEmpty())
			{
	%>
  <div class="row" >
    <div  id="subj" class="collapse in_del">
      <div class="Classification" >
        <div class="panel panel-default">
          <div class="panel-heading" id="sl">
            <%
            		List<Subject> popularList = SubjectService.getPopular(10);
            		if (popularList != null && !popularList.isEmpty())
            		{
            	%>
            <strong style="padding-left:20px">热门题库： <a id="0" style="color:red">全部</a> |
            <%
            		for (Subject sub : popularList)
            		{
            	%>
            <a id="<%=sub.getId()%>"><%=sub.getName()%></a> |
            <%} %>
            </strong></div>
          <%} %>
          <table class="table">
            <%
				for (int i = 0; i < list.size(); i++)
				{
					Subject level1 = list.get(i);
			%>
            <tr>
              <th><%=level1.getName()%></th>
              <td id="sl"><%
					List<Subject> list2 = level1.getChildren();
					if (list2  != null && !list2.isEmpty())
					{
						for (Subject level2 : list2)
						{
				%>
                <a id="<%=level2.getId()%>"><%=level2.getName()%></a> |
                <%}} %></td>
            </tr>
            <%} %>
          </table>
        </div>
      </div>
    </div>
  </div>
  <%} }%>
  
  <!--隐藏选项类别层结束--> 
  
  <!-- 内容开始--> 
  <br/>
  <div class="row">
    <div class="col-sm-1" id="leftFR"><span class="btn btn-link"  data-toggle="collapse" data-target="#subj">更改分类</span></div>
    <div class="col-sm-8">
      <div id="list">
        <%
	        	if (results != null && !results.isEmpty()){
	        	        	String source = "question";
	        	        	if ("2".equals(type)) source = "paper";
	        	        	for (SearchResult r : results){
	        %>
        <ul>
          <li><a class="t" href="<%=context%>/<%=source%>?id=<%=SecureUtil.encryptPassword(r.getId())%>" ><%=r.getTitle()%></a></li>
          <li><a class="t2" href="<%=context%>/paper?id=<%=SecureUtil.encryptPassword(r.getSourceId())%>"><%=r.getSourceName()%></a></li>
          <li><%=r.getContent()%></li>
        </ul>
        <%
	        	}}else{
	        %>
        <div>
          <div class="lead"> <strong>没找到结果~</strong>
            <hr/>
            尝试下改变 关键词 或 <span class="btn btn-primary btn-sm"  data-toggle="collapse" data-target="#subj">&nbsp;改变分类 </span> 看看<br />
          </div>
          <hr />
          <h3>题海使用方法</h3>
          <hr/>
          <dl class="dl-horizontal panel panel-default">
            <dt>所在试卷：</dt>
            <dd>广东2011年高考文科综合(A卷)试题</dd>
            <dt>试题题干：</dt>
            <dd>隋唐以前，官府设有谱局，考定父祖官爵、门第。此后该现象逐步消失，主要原因是</dd>
            <dt>选项：</dt>
            <dd>A、宗法治的终结<br>
              B、察举制的完善<br>
              C、三省六部制的设立<br>
              D、科举制的推行</dd>
          </dl>
          <span  style="color:red" >如果查找试题，在搜索框中输入：“隋唐以前”，然后点搜索 </span><br>
          <img src="includes/images/help.png" class="img-responsive"> <br>
          <span  style="color:red" >如果希望更精确，记得选择题库，缩小范围哦：）<br />如果有改进意见，记得联系我们</span></div>
        <%--  您是搜索
          <button id="typeOption11" onclick="optionSubmit('1')" class="btn btn-primary "><span class="glyphicon glyphicon-pencil"></span> &nbsp; 试题</button>
          还是搜索
          <button id="typeOption22" onclick="optionSubmit('2')" class="btn btn-primary"><span class="glyphicon glyphicon-list-alt"></span> &nbsp; 试卷</button> ？
        </div>--%>
        <%} %>
        <div id="pager" style="height:30px;margin-left:40px; margin-bottom:20px; text-align:left;"> </div>
      </div>
      <div id="pager" style="height:30px; margin-bottom:20px; text-align:left;"></div>
    </div>
    <div class="col-sm-3"><!----></div>
  </div>
  <!--内容结束--> 
  <br/>
  <br/>
  <div class="text-left col-sm-11 col-sm-offset-1">
    <p><a onclick="AddFavorite()" href="#">收藏</a> | <a target="_blank" href="http://wpa.qq.com/msgrd?v=3&uin=1003753463&site=qq&menu=yes">联系我们</a> | <a href="aboutus.html" target="_blank">关于我们</a> | <a href="joinus.html" target="_blank">我要参与</a></p>
    <p> &copy;2013&nbsp;Tihai.org&nbsp;题海科技</p>
  </div>
</div>
<script>
$("#keyword").keypress(function(event){
	if ( event.which == 13 ) {
		_submit();
	}
});

$(document).ready(function() {
	var pager = new PagerView('pager');
	pager.itemCount = <%=pageInfo.getRecordCount()%>;
	pager.size = <%=pageInfo.getCountPerPage()%>;
	pager.index = <%=pageInfo.getPageNum()%>
	pager.render();
	pager.onclick = function(index){
		$('#pnum').val(index);
		_submit();
	};
	
	
	if($('#type').val() == '1'){
		$('#typeOption1').removeClass('btn-default');
		$('#typeOption1').addClass('btn-success');
	}else if($('#type').val() == '2'){
		$('#typeOption2').removeClass('btn-default');
		$('#typeOption2').addClass('btn-success');
	}
});


function optionSubmit(value){
	$('#pnum').val(1);
	$('#type').val(value);
	_submit();
}

function _submit(){
	if ($.trim($("#keyword").val())){
		var path = '<%=context%>/adsearch?';
		path += 'subjectId=' + $("#subjectId").val();
		path += '&type=' + $("#type").val();
		path += '&keyword=' + encodeURI(encodeURI($("#keyword").val()));
		path += '&unkeyword=' + encodeURI(encodeURI($("#unkeyword").val()));
		path += '&pnum=' + $("#pnum").val();
		location.href = path;
	}else{
		location.reload();
	}
}

$('#sl a').click(function(){
	$("#subjectId").val($(this).attr('id'));
	$("#subjectName").html($(this).text());
	$("#subj").collapse('hide');
	
	$('#pnum').val(1);
	_submit();
});

function AddFavorite(){
	var sURL = window.location;
	var sTitle = document.title;
    try{
        window.external.addFavorite(sURL, sTitle);
    }catch (e){
        try{
            window.sidebar.addPanel(sTitle, sURL, "");
        }catch (e){
            alert("加入收藏失败，请使用浏览器收藏功能");
        }
    }
 }
</script> 
<!--统计--> 
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-665718-7', 'tihai.org');
  ga('send', 'pageview');

</script>
</body>
</html>
